//
//  CLReadContentView.m
//  CLBrowser
//
//  Created by 梁慧聪 on 2022/7/21.
//

#import "CLReadContentView.h"

@implementation CLReadContentView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubviews];
    }
    return self;
}

- (void)addSubviews {
    UIControl *cover = [[UIControl alloc]init];
    self.cover = cover;
    cover.alpha = 0;
    cover.userInteractionEnabled = NO;
    cover.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.7];
    [cover addTarget:self action:@selector(clickCover) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:cover];
}

- (void)clickCover {
    self.cover.userInteractionEnabled = NO;
    
    if ([self.delegate respondsToSelector:@selector(contentViewClickCover:)]) {
        [self.delegate contentViewClickCover:self];
    }
    
    [self showCover:NO];
}

/// 遮盖展示
- (void)showCover:(BOOL)isShow {
    
    if (_isShowCover == isShow) { return; }
    
    if (isShow) {
        
        [self bringSubviewToFront:self.cover];
        
        self.cover.userInteractionEnabled = YES;
    }
    
    _isShowCover = isShow;
    [UIView animateWithDuration:CL_READ_AD_TIME animations:^{
        self.cover.alpha = [@(isShow) floatValue];
    }];
}

 - (void)layoutSubviews {
    
     [super layoutSubviews];
    
     self.cover.frame = self.bounds;
}
@end
